package com.four.user.service.impl;

import java.util.List;

import com.four.user.dao.UserDao;
import com.four.user.dao.impl.UserDaoImpl;
import com.four.user.pojo.User;
import com.four.user.service.UserService;

public class UserServiceImpl implements UserService {

	public boolean login(String username, String password) {
		UserDao dao = new UserDaoImpl();
		User u = dao.selectByName(username);
		if(u != null && u.getUsername().equals(username)&&u.getPassword().equals(password)) {
			return true;
		}
		return false;
	}

	@Override
	public List<User> selectAll() {
		UserDao dao = new UserDaoImpl();
		return dao.selectAll();
	}

	@Override
	public User selectById(String id) {
		UserDao dao = new UserDaoImpl();
		int no = Integer.valueOf(id);
		return dao.selectById(no);
	}

	@Override
	public boolean addUser(String username, String password, String age, String gender, String remake) {
		UserDao dao = new UserDaoImpl();
		int a = Integer.valueOf(age);
		int n = dao.addUser(username, password, a, gender, remake);
		return n>0;
	}

	@Override
	public boolean updateUser(String id, String username, String password, String age, String gender, String remake) {
		UserDao dao = new UserDaoImpl();
		int a = Integer.valueOf(age);
		int i = Integer.valueOf(id);
		int n = dao.updateUser(i, username, password, a, gender, remake);
		return n>0;
	}

	@Override
	public boolean deleteUser(String id) {
		UserDao dao = new UserDaoImpl();
		int i = Integer.valueOf(id);
		int n = dao.deleteUser(i);
		return n>0;
	}

}
